import axios from 'axios';
import Qs from 'qs';
//默认表单方式发式
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
axios.defaults.transformRequest = [data => Qs.stringify(data)];

//json方式发送
const json  = {
    headers : {
        "Content-Type" : "application/json",
    },
    transformRequest: [ function (data) {
        return JSON.stringify(data);
    }],
}

const host  = "http://192.168.2.101:8080/plugin-attendance-record";

//签到规则列表
export const rules = (id) => {
    return axios.get(`${host}/rest/rule/all/${id}`)
}

//单个签到规则
export const ruleOne = (id,type) => {
    if(type ==='default'){
        return axios.get(`${host}/rest/rule/default/${id}`)
    }
    return axios.get(`${host}/rest/rule?ruleid=${id}`);
}

//签到对象列表
export const signObj = (id) => {
    return axios.get(`${host}/rest/group/rule/${id}`);
}

//签到对象组
export const signObjGroup = (id) => {
    return axios.get(`${host}/rest/group/all/${id}`);
}

//签到对象成员
export const signObjMember = (id) => {
    return axios.get(`${host}/rest/user/group/${id}`);
}

//签到对象成员
export const signObjUpdate = (id,data) => {
    return axios.post(`${host}/rest/rule/${id}/addgroup`,data,json);
}


//修改签到规则
export const rulesUpdate = (data,isdefault) => {
    if(isdefault === true ){
        return axios.post(`${host}/rest/rule/default/update/`,data,json);
    }
    return axios.post(`${host}/rest/rule/update/`,data,json);
}



